package com.xqboss.chain.domain.chain.dto;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.Max;

/**
 * @author Administrator
 */
@Data
public class BaseRequest {

    /**
     * 当前页码
     */
    @TableField(exist = false)
    @ApiModelProperty(value = "当前页", example = "1")
    private Integer pageNum;

    /**
     * 每页显示记录数
     */
    @ApiModelProperty(value = "每页记录数", example = "10")
    @Max(value = 30, message = "最大支持每页30条")
    @TableField(exist = false)
    private Integer pageSize;

    public Page startPage() {
        if (pageNum == null || pageNum <= 0) {
            pageNum = 1;
        }
        if (pageSize == null || pageSize <= 0) {
            pageSize = 10;
        }
        Page objects = PageHelper.startPage(pageNum, pageSize);
        return objects;
    }

    @ApiModelProperty(hidden = true)
    public Integer getToday() {
        return Integer.parseInt(DateUtil.format(DateUtil.date(), "yyyyMMdd"));
    }

    @ApiModelProperty(hidden = true)
    public Long getNow() {
        return Long.parseLong(DateUtil.format(DateUtil.date(), "yyyyMMddHHmmss"));
    }
}
